package javaClassExercise;

/**
 * Created by lomo on 2017/3/13.
 */
public class equalsCompare {

    public static void main(String[] args) {
        String a = new String("cd");
        String b = new String("cd");

        System.out.println("String使用==比较的结果：" + (a == b) );  // false
        System.out.println("String使用equals比较的结果：" + a.equals(b)); //true

        StringBuffer sb = new StringBuffer("chen");
        StringBuffer sb2 = new StringBuffer("chen");
        System.out.println("StringBuffer使用==比较的结果：" + (sb == sb2) );  // false
        System.out.println("StringBuffer使用equals比较的结果：" + sb.equals(sb2) ); //false

        StringBuilder sbu = new StringBuilder("lomo");
        StringBuilder sbu2 = new StringBuilder("lomo");
        System.out.println("StringBuilder==的比较：" + (sbu == sbu2));  //false
//        try {
//            System.out.println("StringBuilder==的比较：" + (sbu == sbu2));  //false
//        }catch (Exception err){
//            System.out.println(err);
//        }
        System.out.println("StringBuilder使用equals比较：" + sbu.equals(sbu2)); // false
    }
}
